clearListener();
 
---------------------------------------------------------------
-- Load dlls we intend to use
---------------------------------------------------------------
dotNet.loadAssembly "XPTable.dll";
 
---------------------------------------------------------------
-- Define some formating styles
---------------------------------------------------------------
dockStyle = dotNetClass "System.Windows.Forms.DockStyle";
formBorderStyle = dotNetClass "System.Windows.Forms.FormBorderStyle";
colors = dotNetClass "System.Drawing.Color"
gridColor = dotNetClass " XPTable.Models.GridLines"
 
---------------------------------------------------------------
-- create an instance of a Table model, Column model, Table model
---------------------------------------------------------------
table1 = dotNetObject "XPTable.Models.Table";
columnModel1 = dotNetObject "XPTable.Models.ColumnModel";
tableModel1 = dotNetObject "XPTable.Models.TableModel";
 
---------------------------------------------------------------
-- assign the ColumnModel and TableModel to the Table
---------------------------------------------------------------
table1.ColumnModel = columnModel1; 
table1.TableModel = tableModel1;
 
---------------------------------------------------------------
-- set some Table specific properties
---------------------------------------------------------------
table1.Dock = dockStyle.Fill;
table1.FullRowSelect = false;	
table1.BorderColor = colors.Black;
table1.UnfocusedBorderColor = colors.Black;
table1.SortedColumnBackColor = colors.DarkGray;
table1.BackColor = colors.LightGray;
table1.GridColor = colors.Silver;
table1.GridLines = gridColor.Both;
table1.TableModel.RowHeight += 5;
 
---------------------------------------------------------------
-- create an array with each type that will be cancatinated with the xpTableModelText variable
---------------------------------------------------------------
columnModels = #("Text","Button","CheckBox","Image","Number","ProgressBar","ComboBox","DateTime","Color");
xpTableModelText = ("dotNetObject \"XPTable.Models.");
columnWidth = #(70, 65, 90, 24, 50, 100, 80, 130, 110);
 
--------------------------------------------------------------- 
-- define an array to store the the new columns in as well as add them to the columnModel
-- this is just an easier way to generate the required data without having to type 9 lines of basically the same code
-- and use the type as the Column.Text value
---------------------------------------------------------------
columnArray = #();
for i=1 to columnModels.count do 
	(
	columnArray[i] = execute (xpTableModelText + columnModels[i] + "Column\" \"" + columnModels[i] + "\" ");
	columnArray[i].Width = columnWidth[i];
	columnModel1.Columns.Add columnArray[i]
	)
 
---------------------------------------------------------------	
-- a single column without the dynamic building would look like this
---------------------------------------------------------------
columnArray[10] = dotNetObject "XPTable.Models.TextColumn" "Bonus Column";
columnArray[10].Width = 100
columnModel1.Columns.Add columnArray[10];
 
---------------------------------------------------------------
-- we will use a similar approach to creating the rows, using the
-- same xpTableModelText string to build what we need	 
---------------------------------------------------------------
rowCount = 5;
rowArray = #();
cellArray = #();
switcher = false; 
for i=1 to rowCount do 
	(
	rowArray[i] = execute (xpTableModelText + "Row\"");
	rowArray[i].Height = 20;
	tableModel1.Rows.Add rowArray[i];
 
	---------------------------------------------------------------
	-- now we will create the cells and store the results in a multidimensional array
	-- since each column needs a cell we will use the size of the columnArray
	-- to itterate through and create these
	---------------------------------------------------------------
	append cellArray #();
 
	-- Change every other line to a different grey
	if switcher then (bkColor = colors.LightGray; switcher = false;)
	else (bkColor = colors.Gainsboro; switcher  = true;)
 
	for j=1 to columnArray.count  do 
		(
		cellArray[i][j] = execute  (xpTableModelText + "Cell\" \" \"");
		cellArray[i][j].BackColor = bkColor
		)		
	rowArray[i].Cells.AddRange cellArray[i];		
	) 
 
---------------------------------------------------------------
-- Create a MaxForm to add Table control to and add control to form
---------------------------------------------------------------	
form2= dotNetObject "System.Windows.Forms.Form"
form2.topmost=true
form2.Width = 800;
form2.Height = 250;
form2.Controls.Add table1;
form2.Show()